package org.gesplan.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author David
 */
@Entity
@Table(name = "subgroup")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Subgroup.findAll", query = "SELECT s FROM Subgroup s"),
    @NamedQuery(name = "Subgroup.findById", query = "SELECT s FROM Subgroup s WHERE s.id = :id"),
    @NamedQuery(name = "Subgroup.findByCode", query = "SELECT s FROM Subgroup s WHERE s.code = :code"),
    @NamedQuery(name = "Subgroup.findByDescription", query = "SELECT s FROM Subgroup s WHERE s.description = :description")
})
public class Subgroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private String id;
    @Basic(optional = false)
    @Column(name = "code")
    private String code;
    @Basic(optional = false)
    @Column(name = "description")
    private String description;
    @Column(name = "comments")
    private String comments;
    @OneToMany(mappedBy = "subgroupId")
    private Collection<Task> taskCollection;
    @JoinColumn(name = "section_id", referencedColumnName = "id")
    @ManyToOne
    private Section sectionId;        
    @JoinColumn(name = "service_id", referencedColumnName = "id")
    @ManyToOne
    private Service serviceId;

    
    public Subgroup() {  }

    public Subgroup(String id) {
        this.id = id;
    }

    public Subgroup(String id, String code, String description) {
        this.id = id;
        this.code = code;
        this.description = description;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @XmlTransient
    public Collection<Task> getTaskCollection() {
        return taskCollection;
    }

    public void setTaskCollection(Collection<Task> taskCollection) {
        this.taskCollection = taskCollection;
    }

    public Section getSectionId() {
        return sectionId;
    }

    public void setSectionId(Section sectionId) {
        this.sectionId = sectionId;
    }   
    
    public Service getServiceId() {
        return serviceId;
    }

    public void setServiceId(Service serviceId) {
        this.serviceId = serviceId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Subgroup)) {
            return false;
        }
        Subgroup other = (Subgroup) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }

    @Override
    public String toString() {
        return description;
    }
    
    
}